package cn.genmer.test.security.rpc.v2.rpc;

import cn.genmer.test.security.rpc.v2.rpc.protocol.GPackmsg;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentHashMap;

public class ResponseMappingCallback{
    static ConcurrentHashMap<Long, CompletableFuture> mapping  = new ConcurrentHashMap<>();

    public static void addCallBack(Long requestID, CompletableFuture cb){
        mapping.putIfAbsent(requestID,cb);
    }

    public static void runCallBack(Long requestID, GPackmsg packmsg){
//        mapping.get(requestID).run;
        CompletableFuture completableFuture = mapping.get(requestID);
        completableFuture.complete(packmsg.getContent().getRes());
        removeCallBack(requestID);
    }
    public static void removeCallBack(Long requestID){
        mapping.remove(requestID);
    }
}